<?php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    // 指定表名
    protected $table = 'comments';

    // 允许批量赋值的字段
    protected $fillable = ['content', 'user_id', 'post_id'];

    // 禁止批量赋值的字段
    protected $guarded = [];

    // 关联post模型 [一对多反向]
    public function post()
    {
        return $this->belongsTo(Post::class, 'post_id', 'id');
    }

    // 评论所属用户
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }
}
